package com.ruoyi.zhjj.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.web.domain.ApiResponse;
import com.ruoyi.zhjj.domain.ZhjjPersonnelInfo;
import com.ruoyi.zhjj.service.IZhjjPersonnelInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 人员信息，用于记录人员的基本信息和打卡记录Controller
 *
 * @author ruoyi
 * @date 2024-12-28
 */
@RestController
@RequestMapping("/personnel")
public class ZhjjPersonnelInfoController extends BaseController
{
    @Autowired
    private IZhjjPersonnelInfoService zhjjPersonnelInfoService;

    /**
     * 查询人员信息，用于记录人员的基本信息和打卡记录列表
     */
    @RequiresPermissions("zhjj:personnel:list")
    @GetMapping("/list")
    public TableDataInfo list(ZhjjPersonnelInfo zhjjPersonnelInfo)
    {
        startPage();
        List<ZhjjPersonnelInfo> list = zhjjPersonnelInfoService.selectZhjjPersonnelInfoList(zhjjPersonnelInfo);
        return getDataTable(list);
    }

    /**
     * 导出人员信息，用于记录人员的基本信息和打卡记录列表
     */
    @RequiresPermissions("zhjj:personnel:export")
    @Log(title = "人员信息，用于记录人员的基本信息和打卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhjjPersonnelInfo zhjjPersonnelInfo)
    {
        List<ZhjjPersonnelInfo> list = zhjjPersonnelInfoService.selectZhjjPersonnelInfoList(zhjjPersonnelInfo);
        ExcelUtil<ZhjjPersonnelInfo> util = new ExcelUtil<ZhjjPersonnelInfo>(ZhjjPersonnelInfo.class);
        util.exportExcel(response, list, "人员信息，用于记录人员的基本信息和打卡记录数据");
    }

    /**
     * 获取人员信息，用于记录人员的基本信息和打卡记录详细信息
     */
    @RequiresPermissions("zhjj:personnel:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zhjjPersonnelInfoService.selectZhjjPersonnelInfoById(id));
    }

    /**
     * 新增人员信息，用于记录人员的基本信息和打卡记录
     */
    @RequiresPermissions("zhjj:personnel:add")
    @Log(title = "人员信息，用于记录人员的基本信息和打卡记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated ZhjjPersonnelInfo zhjjPersonnelInfo)
    {
        return toAjax(zhjjPersonnelInfoService.insertZhjjPersonnelInfo(zhjjPersonnelInfo));
    }

    /**
     * 修改人员信息，用于记录人员的基本信息和打卡记录
     */
    @RequiresPermissions("zhjj:personnel:edit")
    @Log(title = "人员信息，用于记录人员的基本信息和打卡记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated ZhjjPersonnelInfo zhjjPersonnelInfo)
    {
        return toAjax(zhjjPersonnelInfoService.updateZhjjPersonnelInfo(zhjjPersonnelInfo));
    }

    /**
     * 删除人员信息，用于记录人员的基本信息和打卡记录
     */
    @RequiresPermissions("zhjj:personnel:remove")
    @Log(title = "人员信息，用于记录人员的基本信息和打卡记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhjjPersonnelInfoService.deleteZhjjPersonnelInfoByIds(ids));
    }
}
